﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using TencentCloud.Common;
using TencentCloud.Common.Profile;
using TencentCloud.Sms.V20190711;
using TencentCloud.Sms.V20190711.Models;
using XQ.RequestOfficeSupplies.BLL.Common;
using XQ.RequestOfficeSupplies.WebAPI.Models;

namespace XQ.RequestOfficeSupplies.WebAPI.Controllers.System
{
    /// <summary>
    /// 短信相关接口
    /// </summary>
    public class SMSController : ApiController
    {
        /// <summary>
        /// 短信验证码接口
        /// </summary>
        /// <param name="mobile"></param>
        /// <param name="signName"></param>
        /// <returns></returns>
        [Route("api/SMS/SendVerificationCode")]
        [HttpGet]
        public ResultModel SendMsg(string mobile, string signName)
        {
            ResultModel resultModel = new ResultModel();
            try
            {
                if (!string.IsNullOrEmpty(mobile) && mobile.Length == 11 && signName== "RequestOfficeSupplies@147!")
                {
                    //组装验证码
                    Random rd = new Random();
                    string code = rd.Next(9).ToString() + mobile.Substring(9, 1) + rd.Next(9).ToString() + mobile.Substring(6, 1) + rd.Next(9).ToString() + mobile.Substring(2, 1);

                    resultModel.success = true;
                    resultModel.code = "10000";
                    resultModel.message = "执行成功";
                    string smsContext = "您的短信验证码为：" + code + ", 10分钟之内有效。";
                    resultModel.data = SMSHelper.SendSMS(mobile, "", code);  //QiXinTongHelper.SendSMS(smsSign + smsContext, mobile);
                    return resultModel;
                }
            }
            catch (Exception ex)
            {
                resultModel.success = false;
                resultModel.code = "10001";
                resultModel.message = "执行失败";
                resultModel.data = ex.Message;
            }
            return resultModel;
        }



        ///// <summary>
        ///// 短信状态报告
        ///// </summary>
        ///// <param name="statusReportModel"></param>
        ///// <returns></returns>
        //[Route("api/SMS/StatusReport")]
        //[HttpPost]
        //public string StatusReport([FromBody]StatusReportModel statusReportModel)
        //{
        //    try
        //    {
        //        LogBll.Instance.WriteLog(LogBll.LogType.Search, "", 0, "短信状态报告", "", "", "", "api/SMS/StatusReport：" + JsonConvert.SerializeObject(statusReportModel));
        //        smsBLL.StatusReport(statusReportModel);
        //    }
        //    catch (Exception ex)
        //    {
        //        LogBll.Instance.WriteErrLog("", 0, "短信状态报告报错", "", "", JsonConvert.SerializeObject(statusReportModel), ex.Message, "", "SMSController", "StatusReport");
        //    }

        //    return "SUCCES";
        //}




    }
}